﻿@{
    ViewBag.Title = "ProductTypeAdd";
    Layout = "~/Areas/AdminInfo/Views/Shared/_LayoutPage1.cshtml";
}

@model Gtkj.CMS.Model.ProductType
<div class="container-fluid larry-wrapper">
    <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12">
            <section class="panel panel-padding">

                <form id="form1" class="layui-form layui-form-pane" data-render="true">
                    <div class="layui-form-item">
                        <label class="layui-form-label">分类名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="Name" value="@(Model==null?"": Model.Name)" required jq-verify="required" jq-error="请输入分类名称" placeholder="请输入分类名称" autocomplete="off" class="layui-input ">
                        </div>
                    </div>

                    <div class="layui-form-item" id="ParentType">
                        <label class="layui-form-label">分类</label>
                        <div class="layui-input-inline">
                            <select name="ProductTypeID" id="ProductTypeID" jq-verify="required" jq-error="请输入分类" lay-filter="verify">
                                <option value="">请选择</option>
                                @{
                                    foreach (Gtkj.CMS.Model.ProductType item in ViewBag.ParentList)
                                    {
                                        <option value="@item.TypeID">@item.Name</option>
                                    }
                                }
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item ">
                        <label class="layui-form-label">排名</label>
                        <div class="layui-input-inline">
                            <input type="text" name="Sorting" onkeydown=" if (!(event.keyCode == 46) && !(event.keyCode == 8) && !(event.keyCode == 37) && !(event.keyCode == 39))
     if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)))
         event.returnValue = false;" required jq-verify="number" value="@(Model == null ? 0 : Model.Sorting == null ? 0 : Model.Sorting)" jq-error="排名必须为数字" placeholder="请输入排名" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit="" lay-filter="sub">立即提交</button>
                            @if (Model == null)
                            {
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            }
                        </div>
                    </div>
                    <input type="hidden" name="ID" value="@(Model==null?"":Model.TypeID.ToString())" />
                </form>
            </section>
        </div>
    </div>
</div>
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/Scripts/jquery.url.js"></script>
<script>
    
    var $;
    //var $Type = $("Type");
    layui.use(['form', 'upload', 'jqform'], function () {
       
        $ = layui.jquery,
            jqform = layui.jqform,
         form = layui.form(), layedit = layui.layedit;

        var AddParent = jQuery.url.param("AddParent");
        var AddChild = jQuery.url.param("AddChild");
        var Parent = jQuery.url.param("Parent");
        var ID = jQuery.url.param("ID");
       
        $("#ProductTypeID").val(@(Model != null &&Model.ParamID != 0?Model.ParamID.ToString():""));
        form.render(); //这个很重要
        if (AddParent) {
            $('#ParentType').hide();
        }
        if (AddChild) {
            $('#ParentType').show();
        }
        console.log(Parent);
        if (Parent) {
            $('#ParentType').show();
            if (Parent > 0) {
                $('#ParentType').show();
            } else {
                $('#ParentType').hide();
            }
        }

        form.on('submit(sub)', function (data) {
            $.post('/AdminInfo/AdminSystem/ProductTypeInfo', data.field, function (r) {
                if (r.status == 200) {
                    parent.closeall();
                } else {
                    layer.msg(r.message, { icon: 2 });
                }
            });
            return false;
        });

    });
</script>

